from Util.Vertex import Vertex


class Edge:

    def __init__(self, start, end, time=0, weight=1):
        # start and end can only be the identification of vertex
        self.start = start
        self.end = end
        self.time = time
        self.weight = weight

    def __contains__(self, item):
        if isinstance(item, Vertex):
            item = item.identity
        return (self.start == item) | (self.end == item)

    def start_with(self, node):
        if isinstance(node, Vertex):
            node = node.identity
        return self.start == node

    def get_other(self, node):
        if isinstance(node, Vertex):
            node = node.identity
        if self.start == node:
            return self.end
        return self.start

    def get_vertices(self):
        return [self.start, self.end]

    def get_vertex_pair(self):
        return str(self.start) + str(self.end)
